<template>
	<div class="body">
		<retreat title="登录"></retreat>
		<div class="conter">
			<div>
				<div>用户名</div>
				<input type="text" placeholder="请输入用户名" v-model="username">
			</div>
			<div>
				<div>密码</div>
				<input type="password" placeholder="请输入密码" v-model="password">
			</div>
			<button @click="login">登录</button>
			<router-link to="/register">点击注册</router-link>
		</div>
	</div>
</template>

<script>
	import Retreat from '@/components/Retreat.vue'
	export default {
		data(){
			return{
				username:'',
				password:''
			}
		},
		methods:{
			login(){
				this.$axios.get('http://116.63.80.218/users/checkuser',{
					params:{
						username:this.username,
						password:this.password
					}
				})
				.then(res=>{
					console.log(res.data)
					if(res.data.status===200){
						const userInfo = {userid:res.data.userid,username:res.data.username}
						localStorage.setItem('userInfo',JSON.stringify(userInfo))
						this.$store.state.login=true
						this.$router.go(-1)
						this.$store.state.userName=res.data.username
					}
				})
				.catch(err=>{
					console.log(err)
				})
			}
		},
		components: {
			Retreat
		}
	}
</script>

<style lang="less" scoped>
	@themeColor: #1ba4f0;
	@backColor: #f5f5f5;

	@shenglue: {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.body {
		// min-height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;

		.conter {
			width: 95vw;
			// background-color: @backColor;

			&>div {
				width: 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 6vw;

				&:first-child {
					margin-top: 30vw;
				}

				>div {
					width: 30%;
					color: @themeColor;
					font-weight: 600;
					font-size: 22px;
					text-align: left;
				}

				>input {
					width: 100%;
					height: 10vw;
					border: 1px @themeColor solid;
				}
			}
			button {
				width: 70vw;
				height: 12vw;
				background-color: @themeColor;
				color: #fff;
				border: none;
				margin-top: 10vw;
				border-radius: 2vw;
				font-size: 20px;
			}
			a{
				display: block;
				width: 90vw;
				text-align: right;
				margin-top: 5vw;
			}
		}
	}
</style>
